//
//  Cell.m
//  Game of Life
//
//  Created by James Durkee on 5/12/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "Cell.h"


@implementation Cell
- (id)init {
	self = [super init];
	if (self != nil) {
		isAlive = NO;
	}
	return self;
}

+ (Cell *)cellWithRow:(int)r Col:(int)c {
	Cell *cell = [[Cell alloc] init];
	[cell setRow:r Col:c];
	
	return [cell autorelease];
}

- (NSRect)bounds {
	return bounds;
}
- (void)setBounds:(NSRect)b {
	bounds = b;
}

- (void)setCol:(int)c {
	col = c;
}
- (void)setRow:(int)r {
	row = r;
}
- (void)setRow:(int)r Col:(int)c {
	row = r;
	col = c;
}

- (void)setNcount:(int) n {
	ncount = n;
}

- (void)setNextState:(BOOL) s {
	nextState = s;
}

- (int)row {
	return row;
}
- (int)col {
	return col;
}

- (int)ncount {
	return ncount;
}

- (void)toggleAlive {
	isAlive = !isAlive;
}

- (void)setAlive:(BOOL)b {
	isAlive = b;
}

- (BOOL)isAlive {
	return isAlive;
}

- (BOOL)nextState {
	return nextState;
}

- (void) determineNextState {
	if([self isAlive]){
		if(([self ncount] < 2) || ([self ncount] > 3))
			[self setNextState: NO];
		if([self ncount] == 2 || [self ncount] == 3)
			[self setNextState: YES];
	
	} else {
		
		if([self ncount] == 3)
			[self setNextState: YES];
	}
}

- (void) setAliveToNextState {
	isAlive = nextState;
}

@end